/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.collection;

import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 *
 * @author VANDH
 */
public class DemoQueue {

    private static PriorityQueue hotelQueue = new PriorityQueue();
    private static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
        int choice;

        do {
            System.out.println("1. Thêm một khách sạn");
            System.out.println("2. Xóa khách sạn theo tên");
            System.out.println("3. In ra danh sách");
            System.out.println("4. Thoát");
            choice = keyboard.nextInt();

            switch (choice) {
                case 1:
                    addHotel();
                    break;
                case 2:
                    removeHotel();
                    break;
                case 3:
                    listAllHotel();
                    break;

            }
        } while (choice != 4);
    }

    private static void addHotel() {
        Hotel h;
        do {
            System.out.printf("Hotel %d : ", hotelQueue.size() + 1);
            h = new Hotel();
            h.inputHotel();

            if (!h.hotelName.equals("1")) {
                hotelQueue.offer(h);
            }
        } while (!"1".equals(h.hotelName));
    }

    private static void removeHotel() {
        System.out.println("Khách sạn muốn xóa : ");
        String name = keyboard.next();
        // poll (xóa khỏi hàng đợi) & peek (đọc phần tử đầu tiên)
        Hotel hotel = (Hotel) hotelQueue.poll();
        System.out.println(hotel.toString());
    }

    private static void listAllHotel() {
        for (Object i : hotelQueue) {
            Hotel d = (Hotel) i;
            System.out.println(d.toString());
        }
    }
}
